<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    <title>我的桌面-->常用网址</title>
    <meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
<link rel="stylesheet" href="css/jiangyi/urls.css" type="text/css"></link>
<!-- JQuery UI样式 -->	
<link rel="stylesheet" href="easyui/themes/default/easyui.css" type="text/css"></link>
<!-- JQuery基础脚本库 -->
<script type="text/javascript" src="easyui/jquery-1.8.3.js"></script>
<!-- JQuery　 UI所有的插件脚本库-->
<script type="text/javascript" src="easyui/jquery.easyui.min.js"></script>
<script type="text/javascript">
$(function(){
	$("#adddlg").dialog({closed:true});
	$("#updatedlg").dialog({closed:true});	
	$("#deletedlg").dialog({closed:true});	
	
	$("#dg").datagrid({	  		
		url:"urls/findAll.do?id="+$("#adduserId").val(),
		striped:true,	  			
		rownumbers:true,
		pagination:true,
		pageList:[5,10,15],
		/*frozenColumns : [ [ {  
                field : "ck",  
                checkbox : true  
         } ] ], */  
		columns:[[{
			title:"网址名称",
			field:"name",
			width:300,
			align:"center"
		},{
			title:"网址",
			field:"url",
			width:350,
			align:"left",
			formatter:function (value){
				return "<a href='"+value+"' target='_blank'>"+value+"</a>";
			}
		},{
			title:"操作",
			field:"userid",
			width:103,
			align:"center",
			formatter:function (value,row,index){
				return "<a onclick='update("+row.id+")' href='javascript:void(0)'>修改</a>&nbsp;&nbsp;<a onclick='del("+row.id+")' href='javascript:void(0)'>删除</a>";
			}
		}]]	
	});
//点击添加 --添加常用地址
$("#adds").click(function(){
  	$("#adddlg").dialog("open");
});
$("#adddlg").dialog({
    title: "<img src='images/jiangyi/tDesktop/u188.png'/> 添加地址",
    width: 400,
    height:200,
    closed: true,
    buttons:[{
		text:"保存",
		handler:function(){
			var data ="name="+$("#addname").val()+
 				"&url="+$("#addurl").val()+
 				"&userId="+$("#adduserId").val();
			$.get("urls/add.do",data,function(data){
						alert(data);
						$("#adddlg").dialog("close");
						$("#dg").datagrid("reload");
					},"text");  	
		}
	},{
		text:"取消",
		handler:function(){
			$("#adddlg").dialog("close");
		}
	}]
});			
//修改地址
$("#updatedlg").dialog({
	    title: "修改便签",
	    width: 400,
	    height:200,
	    closed: true,
	    buttons:[{
			text:"修改",
			handler:function(){
				var data ="id="+$("#updateid").val()+
				"&name="+$("#updatename").val()+
  				"&url="+$("#updateurl").val();
				$.get("urls/update.do",data,function(data){
						alert(data);
						$("#updatedlg").dialog("close");
						$("#dg").datagrid("reload");
						},"text");  	
			}
		},{
			text:"取消",
			handler:function(){
				$("#updatedlg").dialog("close");
			}
		}]
	});	
		
});

//修改地址
function update(value){
		$("#updatedlg").dialog("open");	
		$.post("urls/findById.do","id="+value,function(data){
			$("#updateid").val(value);
			$("#updatename").val(data.name);
			$("#updateurl").val(data.url);
		},"json");
	};
//删除地址
function del(value){
	$.messager.confirm("提示框", "你确定要删除吗?",function(r){
		if(r){
			var data = "id="+value;
				$.post(
	  				"urls/delete.do",
	  				data,
	  				function(data){
	  				alert(data);
	  				$("#dg").datagrid("reload");
	  				},
	  				"text"
	  			);
			}
	});
};
	    
</script>  
</head>

<body style="background:url(images/jiangyi/tDesktop/bg.png)">

<div id="mycontent" >

	
	<p><img src="images/jiangyi/tDesktop/u89.png"/>&nbsp;&nbsp;<span><a href="javascript:window.location.href='jsp/tDesktop.jsp'">我的桌面</a></span></p>
	    <div class="title">
	        	<a href="javascript:;">常用网址</a>
	    </div>
		
	<div id="urlslist">
		<ul class="tabletitle">
				<li class="headtitle">常用网址列表</li>
				<li id="adds">
					<img src="images/jiangyi/tDesktop/u130.png"/>
					<a id="add" href="javascript:;">添加</a>
				</li>
		</ul>
		<div id="showInfo">
			<table id="dg"></table>
		</div>	
			<table id="adddlg">
	      		<tr>
	      			<td>标题</td>
	      			<td>
	      				<input style="width:300px;" type="text" name="addname" id="addname"/>
	      			</td>
	      		</tr>
	      		<tr>
	      			<td>链接</td>
	      			<td>
	      				<input style="width:300px;" type="text" name="addurl" id="addurl"/>
	      			</td>
	      		</tr>
	      		<tr>
	      			<td>用户名</td>
	      			<td>
	      				<input type="hidden" value="${user.id}" id="adduserId" />
	      				<input value="${user.name}" style="width:300px;" type="text" name="adduserId" id="adduserId"/>
	      			</td>
	      		</tr>
	      	</table>
	      	<table id="updatedlg">
	      		<tr>
	      			<td>标题</td>
	      			<td>
	      				<input type="hidden" name="urls.id" id="updateid">
	      				<input style="width:300px;" type="text" name="updatename" id="updatename">
	      			<br/>
	      			</td>
	      		</tr>
	      		<tr>
	      			<td>链接</td>
	      			<td>
	      				<input style="width:300px;" type="text" name="updateurl" id="updateurl"/>
	      				<br/>
	      			</td>
	      		</tr>
	      	</table>
      
	</div>
</div>

</body>
</html>
